package com.wuwei.elearning.config.factory;

import com.wuwei.elearning.config.AiConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 工厂类，用于创建不同类型的AI客户端
 */
@Component
@Slf4j
public class AiClientFactory {

    @Autowired
    private AiConfig aiConfig;

    /**
     * 根据配置创建适当的AI客户端
     * @return 对应类型的AI客户端实例
     */
    public AiClient createClient() {
        String provider = aiConfig.getProvider().toLowerCase();
        log.info("Creating AI client for provider: {}", provider);
        
        switch (provider) {
            case "openai":
                return new OpenAiClient(aiConfig);
            case "azure":
                return new AzureOpenAiClient(aiConfig);
            case "bailian":
                return new BailianClient(aiConfig);
            default:
                log.error("Unsupported AI provider: {}", provider);
                throw new IllegalArgumentException("Unsupported AI provider: " + provider);
        }
    }
} 